//
//  QTAboutViewController.m
//  qdqts
//
//  Created by centling on 14-6-23.
//  Copyright (c) 2014年 seas.cheng. All rights reserved.
//

#import "QTAboutViewController.h"
#import "QTAboutTableViewCell.h"
#import "QTClient.h"


static NSString *cellStr = @"QTAboutTableViewCell";
AboutUsInfo *QTAboutUsInfo;

@interface QTAboutViewController ()

@end

@implementation QTAboutViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.

//    [self.usVC registerClass:[QTAboutTableViewCell class] forCellReuseIdentifier:cellStr];
    self.navigationItem.title=@"关于我们";
//    [[QSClient instance] loadAboutUsInfocompletionBlock:^(AboutUsInfo *aboutUsInfo, NSError *error){
//        self.aboutUsInfo = aboutUsInfo;
//        NSLog(@"%@",self.aboutUsInfo);
//        [self.usVC reloadData];
//    }];
    
    self.usVC.scrollEnabled = NO;

    UINib *nib=[UINib nibWithNibName:cellStr bundle:nil];
    [self.usVC registerNib:nib forCellReuseIdentifier:cellStr];

}
-(void)viewWillAppear:(BOOL)animated{
    
    //if(self.aboutUsInfo == nil)
    {
        [[QSClient instance] loadAboutUsInfocompletionBlock:^(AboutUsInfo *aboutUsInfo, NSError *error){
            self.aboutUsInfo = aboutUsInfo;
            NSLog(@"%@",self.aboutUsInfo);
            [self.usVC reloadData];
        }];
    }

    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

{
    return 43;
}


- (NSInteger) numberOfSectionsInTableView: (UITableView *)tableView
{
    return 1;
}

- (NSInteger) tableView: (UITableView *)tableView numberOfRowsInSection: (NSInteger)section
{
    return 3;
}

- (UITableViewCell *) tableView: (UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
//    QTAboutTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellStr]];
//    QTAboutTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellStr forIndexPath:indexPath];
    
    QTAboutTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellStr];
    
    if (cell == nil) {
        cell = [[QTAboutTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellStr];
    }
    
    cell.selectionStyle = NO;
    switch (indexPath.row)
    {
        case 0:
            cell.keyLabel.text = @"联系电话：";
            cell.valueLabel.text = self.aboutUsInfo.aboutUs.phone;
            break;
            
        case 1:
            cell.keyLabel.text = @"官       网：";
            cell.valueLabel.text = self.aboutUsInfo.aboutUs.url;
            break;
            
        case 2:
            cell.keyLabel.text = @"检查更新：";
            cell.valueLabel.text = self.aboutUsInfo.aboutUs.version;
            break;
    }

    return cell;
}

@end
